package J2ME_LoverTest;

import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;

public class GameOverCanvas  extends GameCanvas implements CommandListener{

	private int score;
	private Graphics gc;
	private LoverTestMIDlet ltm;
	private Command cmdExit=new Command("Exit",Command.EXIT,1);
	private Command cmdBack=new Command("Replay",Command.SCREEN,1);
	private Image lostlove,loverscore;
	
	
	
	protected GameOverCanvas(LoverTestMIDlet ltm,int score ) {
		super(true);
		gc=this.getGraphics();
		this.ltm=ltm;
		this.score=score;
		this.addCommand(cmdBack);
		this.addCommand(cmdExit);
		this.setCommandListener(this);
		try {
			lostlove=Image.createImage("/lostlove.png");
			loverscore=Image.createImage("/loverscore.png");
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		identify();
		
	}
	
	public void identify(){
		gc.setColor(0,0,0);
		gc.fillRect(0,0,this.getWidth(),this.getHeight());
		gc.setColor(255,0,0);
		if(score>=50){
		 gc.drawImage(loverscore, 0, 0, 0);
		 gc.drawString(""+score,this.getWidth()/2-2, this.getHeight()-20, 0);
		}
		else gc.drawImage(lostlove, 0, 0, 0);
	}

	public void commandAction(Command c, Displayable d) {
		if(c==cmdExit){
			ltm.notifyDestroyed();
		}
		else if(c==cmdBack){
			ltm.changeInterface("ChoiceHostList");
			
		}
	}

}
